from typing import Any, Union

import pyautogui
global region_left, region_top, region_width, region_height, pyautogui_confidence
# 在pyautogui的识别函数中使用的用于限制范围的四个数值
region_left = 1471 #区域的左上角的横坐标
region_top  = 45 #区域的左上角的纵坐标
region_width = 200 #区域的宽度
region_height = 755 #区域的高度
pyautogui_confidence = 0.36 #识别的匹配度设置

# 敌战巡,返回值为一个列表，包含数量与坐标
def locate_enemy_battlecruiser():
    try:
        cnt = 0
        location = []
        for pos in pyautogui.locateAllOnScreen('Memory/battlecruiser_red.png', confidence= pyautogui_confidence, region=(region_left, region_top, region_width, region_height)):
            cnt += 1
            location.append(pyautogui.center(pos))
    except pyautogui.ImageNotFoundException:
        return 'None'
    else:
        return cnt, location
    #return pyautogui.locateCenterOnScreen('../../../src/icon/icons/battlecruiser_red.png', confidence=0.8, region=(1471, 45, 200, 755))

# 敌战列
def locate_enemy_battleship():
    try:
        cnt = 0
        location = []
        for pos in pyautogui.locateAllOnScreen('Memory/battleship_red.png', confidence= pyautogui_confidence, region=(region_left, region_top, region_width, region_height)):
            cnt += 1
            location[cnt] = pyautogui.center(pos)
    except pyautogui.ImageNotFoundException:
        return 'None'
    else:
        return cnt, location
    #return pyautogui.locateCenterOnScreen('../../../src/icon/icons/battleship_red.png', confidence=0.8, region=(1471, 45, 200, 755))

# 敌巡洋
def locate_enemy_cruiser():
    try:
        cnt = 0
        location = []
        for pos in pyautogui.locateAllOnScreen('Memory/cruiser_red.png', confidence= pyautogui_confidence, region=(region_left, region_top, region_width, region_height)):
            cnt += 1
            location[cnt] = pyautogui.center(pos)
    except pyautogui.ImageNotFoundException:
        return 'None'
    else:
        return cnt, location
    #return pyautogui.locateCenterOnScreen('../../../src/icon/icons/cruiser_red.png', confidence=0.8, region=(1471, 45, 200, 755))

# 敌驱逐
def locate_enemy_destroyer():
    try:
        cnt = 0
        location = []
        for pos in pyautogui.locateAllOnScreen('Memory/destroyer_red.png', confidence= pyautogui_confidence, region=(region_left, region_top, region_width, region_height)):
            cnt += 1
            location[cnt] = pyautogui.center(pos)
    except pyautogui.ImageNotFoundException:
        return 'None'
    else:
        return cnt, location
    #return pyautogui.locateCenterOnScreen('../../../src/icon/icons/destroyer_red.png', confidence=0.8, region=(1471, 45, 200, 755))

# 敌无畏
def locate_enemy_dreadnought():
    try:
        cnt = 0
        location = []
        for pos in pyautogui.locateAllOnScreen('Memory/dreadnought_red.png', confidence= pyautogui_confidence, region=(region_left, region_top, region_width, region_height)):
            cnt += 1
            location[cnt] = pyautogui.center(pos)
    except pyautogui.ImageNotFoundException:
        return 'None'
    else:
        return cnt, location
    #return pyautogui.locateCenterOnScreen('../../../src/icon/icons/dreadnought_red.png', confidence=0.8, region=(1471, 45, 200, 755))

# 敌护卫
def locate_enemy_frigate():
    try:
        cnt = 0
        location = []
        for pos in pyautogui.locateAllOnScreen('Memory/frigate_red.png', confidence= pyautogui_confidence, region=(region_left, region_top, region_width, region_height)):
            cnt += 1
            location[cnt] = pyautogui.center(pos)
    except pyautogui.ImageNotFoundException:
        return 'None'
    else:
        return cnt, location
    #return pyautogui.locateCenterOnScreen('../../../src/icon/icons/frigate_red.png', confidence=0.8, region=(1471, 45, 200, 755))

# 小行星带（00刷怪场所）
def locate_asteroids():
    try:
        location = pyautogui.locateCenterOnScreen('Memory/asteroids.png', confidence=0.8, region=(1471, 45, 200, 755))
    except pyautogui.ImageNotFoundException:
        return 'No result for asteroids'
    else:
        return location
    #return pyautogui.locateCenterOnScreen('../../../src/icon/icons/asteroids.png', conidence=0.8, region=(1471,45,200,755))
